﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class wjmm : System.Web.UI.Page
{

    DataClassesDataContext db = new DataClassesDataContext();
    private string ansOne;
    private string ansTwo;
    private string wbh;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
   
         var result = (from p in db.proc_GetSecurity(TextBox1.Text.ToString().Trim())
                      select p).ToList();
        if (result.Count() == 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('手机号输入错误！');</script>");
        }
        else
        {
            ansOne = result.First().ansOne;
            ansTwo = result.First().ansTwo;
            wbh = result.First().wbh;
            Panel1.Visible = true;
            switch (result.First().questionOne)
            {
                case 1:
                    Label1.Text = "您的学号（或工号）是？";
                    break;
                case 2:
                    Label1.Text = "您母亲的姓名是？";
                    break;
                case 3:
                    Label1.Text = "您母亲的生日是？";
                    break;
                case 4:
                    Label1.Text = "您父亲的姓名是？";
                    break;
                case 5:
                    Label1.Text = "您父亲的生日是？";
                    break;
                case 6:
                    Label1.Text = "您高中班主任的名字是？";
                    break;
                case 7:
                    Label1.Text = "您初中班主任的名字是？";
                    break;
                case 8:
                    Label1.Text = "您小学班主任的名字是？";
                    break;
                case 9:
                    Label1.Text = "您最熟悉的童年好友名字是？";
                    break;
                case 10:
                    Label1.Text = "您最熟悉的学校宿舍室友名字是？";
                    break;
                case 11:
                    Label1.Text = "对您影响最大的人名字是？";
                    break;
                default:
                    Label1.Text = "";
                    break;
            }
            switch (result.First().questionTwo)
            {
                case 1:
                    Label2.Text = "您的学号（或工号）是？";
                    break;
                case 2:
                    Label2.Text = "您母亲的姓名是？";
                    break;
                case 3:
                    Label2.Text = "您母亲的生日是？";
                    break;
                case 4:
                    Label2.Text = "您父亲的姓名是？";
                    break;
                case 5:
                    Label2.Text = "您父亲的生日是？";
                    break;
                case 6:
                    Label2.Text = "您高中班主任的名字是？";
                    break;
                case 7:
                    Label2.Text = "您初中班主任的名字是？";
                    break;
                case 8:
                    Label2.Text = "您小学班主任的名字是？";
                    break;
                case 9:
                    Label2.Text = "您最熟悉的童年好友名字是？";
                    break;
                case 10:
                    Label2.Text = "您最熟悉的学校宿舍室友名字是？";
                    break;
                case 11:
                    Label2.Text = "对您影响最大的人名字是？";
                    break;
                default:
                    Label2.Text = "";
                    break;
            }
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        var result = (from p in db.proc_GetSecurity(TextBox1.Text.ToString().Trim())
                      select p).ToList();
        ansOne = result.First().ansOne;
        ansTwo = result.First().ansTwo;
        wbh = result.First().wbh;
        if (TextBox2.Text.ToString() == ansOne && TextBox3.Text.ToString() == ansTwo)
        {
            if (db.proc_ResetStuPwd(wbh) == -1)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('密码找回失败，请重试！');</script>");
            }
            else
            {
                db.SubmitChanges();
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('密码已初始化为身份证的后六位！');window.location='/zsb作业1/login.aspx';</script>");
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('密保问题答案错误！');</script>");
        }
    }
}